package com.guys8.cemsbackend.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guys8.cemsbackend.DTO.UserInformation;
import com.guys8.cemsbackend.entity.Account;
import com.guys8.cemsbackend.entity.ClassUser;
import com.guys8.cemsbackend.mapper.UserMapper;
import com.guys8.cemsbackend.entity.User;
import com.guys8.cemsbackend.service.UserService;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * (User)表服务实现类
 *
 * @author breeze
 * @since 2022-08-24 16:53:22
 */
@Service("userService")
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    public User getbyschoolid(String schoolid){
        Map<String,Object> userMap = new HashMap<>();
        userMap.put("school_id", schoolid);
        List<User> users = this.listByMap(userMap);
        if(users.size()<1)
            return null;
        User user = users.get(0);
        return user;
    }

    public List<UserInformation> getstudents(List<ClassUser> cstus) {
        List<UserInformation> users = new LinkedList<>();
        for(ClassUser cu:cstus){
            users.add(new UserInformation(getById(cu.getUserId())));
        }
        return  users;
    }

}

